#include <jni.h>
#include <string>
#include "SafeQueue.h"
#include "HaoFFmpeg.h"

extern "C" {
#include <libavcodec/avcodec.h>
}

HaoFFmpeg *haoFFmpeg = nullptr;
JavaVM *javaVm;

int JNI_OnLoad(JavaVM *vm, void *unused) {
    javaVm = vm;
    return JNI_VERSION_1_6;
}

extern "C"
JNIEXPORT jstring JNICALL
Java_com_zzh_live_MainActivity_stringFromJNI(JNIEnv *env, jobject thiz) {
    return env->NewStringUTF(av_version_info());
}



extern "C"
JNIEXPORT void JNICALL
Java_com_zzh_live_HaoPlayer_prepareNative(JNIEnv *env, jobject thiz, jstring data_source) {
    //GetStringUTFChars对应释放ReleaseStringUTFChars
    const char *datasource = env->GetStringUTFChars(data_source, nullptr);
    JavaCallback *javaCallback = new JavaCallback(javaVm, env, thiz);
    haoFFmpeg = new HaoFFmpeg(datasource, javaCallback);
    haoFFmpeg->prepare();
    env->ReleaseStringUTFChars(data_source, datasource); //释放字符串
}